//
//  WLDownLoadSubControllerViewController.m
//  WanLian
//
//  Created by 123456 on 2018/12/8.
//  Copyright © 2018 wanlian. All rights reserved.
//

#import "WLDownLoadSubControllerViewController.h"
#import "WLDownLoadCenter.h"
#import "WLUpDownloadTaskCell.h"
#import "WLUpDownloadedTaskCell.h"

@interface WLDownLoadSubControllerViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSArray *tasksArray;
@property (nonatomic, strong) NSMutableArray *loadedArray;
@end

@implementation WLDownLoadSubControllerViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self creatTableView];
}
- (NSArray *)tasksArray {
    return [[WLDownLoadCenter shareInstance] getTasksArray];
}
- (void)creatTableView
{
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, Screen_width, Screen_height -EQ_StatusBarAndNavigationBarHeight) style:UITableViewStylePlain];
    self.tableView.backgroundColor = rgba(249, 249, 249, 1);
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.showsVerticalScrollIndicator = NO;
    self.tableView.scrollEnabled = YES;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.view addSubview:self.tableView];
    
//    [self creatTableViewHeader:self.tableView];
//    self.tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(footerRefresh)];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        return self.tasksArray.count;
    } else {
        return self.loadedArray.count;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        WLUpDownloadTaskCell *taskCell = [WLUpDownloadTaskCell createCellWithTableView:tableView cellIndetifier:@"WLUpDownloadTaskCell"];
        WLFileUpDownLoadModel *model = [self.tasksArray objectAtIndex:indexPath.row];
        taskCell.model = model;
        return taskCell;
    } else if (indexPath.section == 1){
        WLUpDownloadedTaskCell *loadedTaskCell = [WLUpDownloadedTaskCell createCellWithTableView:tableView cellIndetifier:@"WLUpDownloadedTaskCell"];
        WLFileUpDownLoadModel *model = [self.tasksArray objectAtIndex:indexPath.row];
        loadedTaskCell.model = model;
        return loadedTaskCell;
    }
    return nil;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 68;
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
}

@end
